﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace WebAppFilterDemo.FilterExt
{

    /// <summary>
    /// 授权过滤器
    /// </summary>
    public class AuthonizationFilter : Attribute, IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationFilterContext context)
        {

            ////这里可做复杂的权限控制操作
            //if (context.HttpContext.User.Identity.Name != "admin")
            //{

            //    //未验证通过的跳转到无权限提示页面
            //    //RedirectToActionResult content = new RedirectToActionResult("NoAuth", "Exception", null);

            //    var content =  new ObjectResult("无权限");
            //    context.Result = content;
            //}

            Console.WriteLine("AuthonizationFilter - OnAuthorization");
        }
    }
}
